package demo1.Assignment1;

/**
 * 构建NpuInfo类，该类中三个成员变量：
 * name：”西北工业大学”
 * address：” 西安市友谊西路127号”
 * telephone：”029-88494433”
 * 在系统中均不会发生变化，请采用单例模式构建该类
 */
public class NpuInf {
    private String name;
    private String address;
    private String telephone;

    //定义一个变量来存储创建好的类实例
    private static NpuInf npuInf = null;

    //私有化构造器，防止外部调用
    private NpuInf(String name, String address, String telephone) {
        this.name = name;
        this.address = address;
        this.telephone = telephone;
    }

    public String getName() {
        return name;
    }


    public String getAddress() {
        return address;
    }


    public String getTelephone() {
        return telephone;
    }


    @Override
    public String toString() {
        return "NpuInf{" +
                "name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", telephone='" + telephone + '\'' +
                '}';
    }

    //给外界要给创建对象的通道
    public static NpuInf getNpuInf() {
        if (npuInf == null) {
            npuInf = new NpuInf("西北工业大学", "西安市友谊西路127号", "029-88494433");
        }
        return npuInf;
    }
}
